package com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog;

import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.StudentChangeLogCreateReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.StudentChangeLogExcelVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.StudentChangeLogExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.StudentChangeLogPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.StudentChangeLogRespVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.StudentChangeLogUpdateReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchangelog.vo.*;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.studentchangelog.StudentChangeLogDO;
import com.nanhai.buddhist.college.module.collegebase.convert.studentchangelog.StudentChangeLogConvert;
import com.nanhai.buddhist.college.module.collegebase.service.studentchangelog.StudentChangeLogService;

@Api(tags = "管理后台 - 信息异动记录")
@RestController
@RequestMapping("/collegebase/student-change-log")
@Validated
public class StudentChangeLogController {

    @Resource
    private StudentChangeLogService studentChangeLogService;

    @PostMapping("/create")
    @ApiOperation("创建信息异动记录")
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:create')")
    public CommonResult<String> createStudentChangeLog(@Valid @RequestBody StudentChangeLogCreateReqVO createReqVO) {
        return success(studentChangeLogService.createStudentChangeLog(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新信息异动记录")
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:update')")
    public CommonResult<Boolean> updateStudentChangeLog(@Valid @RequestBody StudentChangeLogUpdateReqVO updateReqVO) {
        studentChangeLogService.updateStudentChangeLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除信息异动记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:delete')")
    public CommonResult<Boolean> deleteStudentChangeLog(@RequestParam("id") String id) {
        studentChangeLogService.deleteStudentChangeLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得信息异动记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:query')")
    public CommonResult<StudentChangeLogRespVO> getStudentChangeLog(@RequestParam("id") String id) {
        StudentChangeLogDO studentChangeLog = studentChangeLogService.getStudentChangeLog(id);
        return success(StudentChangeLogConvert.INSTANCE.convert(studentChangeLog));
    }

    @GetMapping("/list")
    @ApiOperation("获得信息异动记录列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:query')")
    public CommonResult<List<StudentChangeLogRespVO>> getStudentChangeLogList(@RequestParam("ids") Collection<String> ids) {
        List<StudentChangeLogDO> list = studentChangeLogService.getStudentChangeLogList(ids);
        return success(StudentChangeLogConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得信息异动记录分页")
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:query')")
    public CommonResult<PageResult<StudentChangeLogRespVO>> getStudentChangeLogPage(@Valid StudentChangeLogPageReqVO pageVO) {
        PageResult<StudentChangeLogDO> pageResult = studentChangeLogService.getStudentChangeLogPage(pageVO);
        return success(StudentChangeLogConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出信息异动记录 Excel")
    @PreAuthorize("@ss.hasPermission('collegebase:student-change-log:export')")
    @OperateLog(type = EXPORT)
    public void exportStudentChangeLogExcel(@Valid StudentChangeLogExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<StudentChangeLogDO> list = studentChangeLogService.getStudentChangeLogList(exportReqVO);
        // 导出 Excel
        List<StudentChangeLogExcelVO> datas = StudentChangeLogConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "信息异动记录.xls", "数据", StudentChangeLogExcelVO.class, datas);
    }

}
